package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface UserMapper extends BaseMapper<User> {

    @Select("select id,username,password from t_user where username=#{username}")
    UserVO findUserIdByUsername(@Param("username") String username);

    @Select("SELECT tr.ID,tr.KEYWORD " +
            "FROM t_user_role tur,t_role tr " +
            "WHERE tur.ROLE_ID=tr.ID " +
            "and tur.USER_ID=#{uid} ")
    List<RoleVO> findUserRolesByUserId(@Param("uid") Integer uid);

    @Select("SELECT tp.KEYWORD " +
            "FROM t_role_permission trp,t_permission tp " +
            "WHERE trp.PERMISSION_ID=tp.ID " +
            "and trp.ROLE_ID=#{id}")
    List<Permission> findUserPermissionByRoleId(@Param("id") Integer id);



    /* 动态展示菜单
    todoby 董子帆
    */
    @Select("select id,username,password from t_user where username =#{username}")
    UserVO findUserInfoByUsername(@Param("username")String username);

    @Select("select tr.id,tr.keyword from t_role tr,t_user_role tur where tur.role_id = tr.id and tur.user_id = #{id}")
    List<RoleVO> findRolesByUid(@Param("id") Integer id);

    @Select("select tm.id from t_menu tm,t_role_menu trm where tm.id = trm.menu_id and trm.role_id = #{id}")
    List<Integer> findMenuIdByRoleId(@Param("id")Integer id);
}
